package com.dodoke.controller;

import java.util.List;

import com.dodoke.common.core.domain.AjaxResult;
import com.dodoke.domain.WxQrGoods;
import com.dodoke.service.IWxQrGoodsService;
import io.swagger.annotations.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.dodoke.common.core.controller.BaseController;
import com.dodoke.common.core.page.TableDataInfo;

/**
 * 【二维码-商品】Controller
 * 
 * @author dodoke
 * @date 2020-08-25
 */
@RestController
@RequestMapping("/qr_goods")
@Api("二维码-商品模块")
public class WxQrGoodsController extends BaseController
{
    @Autowired
    private IWxQrGoodsService wxQrGoodsService;

    /**
     * 查询【二维码商品】列表
     */
    @PreAuthorize("@ss.hasPermi('wx:qr_goods:list')")
    @GetMapping("/list")
    public TableDataInfo list(WxQrGoods wxQrGoods)
    {
        startPage();
        List<WxQrGoods> list = wxQrGoodsService.selectWxQrGoodsList(wxQrGoods);
        return getDataTable(list);
    }

    /***
     * 新增商品到对应的二维码
     * @param addIds 增加的商品id集合
     * @param delIds 删减的商品id集合
     * @return
     */
    @ApiOperation("为二维码添加商品")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "addIds",dataType = "Array",value = "增加的商品id集合",paramType = "body"),
            @ApiImplicitParam(name = "delIds",dataType = "Array",value = "删减的商品id集合",paramType = "body"),
            @ApiImplicitParam(name = "id",dataType = "int",value = "小程序码id",paramType = "path")
    })
    @ApiResponses({
            @ApiResponse(code = 200,message = "新增商品成功"),
            @ApiResponse(code = 500,message = "新增商品失败")
    })
    @RequestMapping(value = "/insertQrGoods/{id}",method = RequestMethod.PUT)
    public AjaxResult insertQrGoods(@PathVariable Long id, @RequestParam("addIds") List<Long> addIds,
                                    @RequestParam("delIds") List<Long> delIds) {
        int affectNum = wxQrGoodsService.insertWxQrGoods(id,addIds,delIds);
        return toAjax(affectNum);
    }

}
